<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增短信提醒电话')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-smsphone-add">
            <div class="form-group">
                <textarea id="pid" class="form-control" type="text" style="display: none">[[${pid}]]</textarea>
                <label class="col-sm-3 control-label">选择产品：</label>
                <div class="col-sm-8">
                    <!--<select id="productId" class="form-control" name="productId"></select>-->
                    <select id="cp" name="cp" class="form-control noselect2 selectpicker" data-none-selected-text="产品" multiple>
                        <option th:each="dict : ${cp}" th:text="${dict.productName}" th:value="${dict.id}"></option>
                    </select>
                </div>
                <label class="col-sm-3 control-label">选择联系人：</label>
                <div class="col-sm-8">
                    <!--<select id="productId" class="form-control" name="productId"></select>-->
                    <select id="productId" name="productId" class="form-control noselect2 selectpicker" data-none-selected-text="选择联系人" multiple>
                        <option th:each="dict : ${data}" th:text="${dict.loginName}" th:value="${dict.userId}"></option>
                    </select>
                </div>
                *只展示有电话的用户

            </div>
            <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>

           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">联系人：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">电话：</label>
                <div class="col-sm-8">
                    <input name="phone" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="bz" class="form-control" type="text">
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        //var pid = [[${pid}]]
        var prefix = ctx + "system/smsphone"
        $("#form-smsphone-add").validate({
            focusCleanup: true
        });
        var p = ctx +"system/user"
       // setTimeout(function() {
        /*    console.log("延时1秒后执行");
            $.get(p+"/getuserphone",function (data){
                console.log("开始")
                if(data.data.length>0){
                    for (let i = 0; i < data.data.length; i++) {
                        if(data.data[i].phonenumber.length>0){
                            $('#productId').append(`<option value="`+data.data[i].userId+`">`+data.data[i].loginName +`</option>`);
                        }
                    }
                }
            })*/
       // }, 2000);
        function submitHandler() {
            console.log("测试")
            var pid1 = $("#cp").val()
            var pid = $("#pid").val()
            var lxr = $("#productId").val()
            console.log(pid)
            console.log(lxr)
          /*  if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-smsphone-add').serialize());
            }*/

        }

        function submitHandler() {
                    var pid1 = $("#cp").val()//产品
                    var cpata = "";
                    for (let i = 0; i < pid1.length; i++) {
                        cpata += pid1[i]+","
                    }
                    var pid = $("#pid").val()
                    var phone = $("#productId").val()
                        console.log(pid)
                        console.log(phone)
                        var pdata = "";
                        for (let i = 0; i < phone.length; i++) {
                            pdata += phone[i]+","
                        }
                    $.operate.saveTab(prefix + "/addsj", {pid:cpata,phone:pdata},function (e){
                        //alert(e)
                    });
        }
    </script>
</body>
</html>